package com.wondream.plumelog.example.log4j2.service.impl;

import com.plumelog.trace.annotation.Trace;
import com.wondream.plumelog.example.log4j2.service.TestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author wangjun
 * @note TestServiceImpl
 * @date 2023-10-23  17:18
 */
@Service
//@Slf4j
public class TestServiceImpl implements TestService {

    private static final Logger log = LoggerFactory.getLogger(TestServiceImpl.class);

    @Value("${server.port}")
    private String port;

    @Override
    public String hello(String name) {
        String result = String.format("hello:%s", name);
        log.info(result);
        return result;
    }

    @Override
    @Trace
    public String info() {
        String host = null;
        try {
            host = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            host = "未知";
        }
        String result = String.format("%s:%s", host, port);
        log.info(result);
        return result;
    }
}
